﻿using Coldairarrow.Business.Base_leasesystem_merchant;
using Coldairarrow.Business.Base_leasesystem_merchant_img;
using Coldairarrow.Entity.Base_leasesystem_merchant;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.ViewModel;
using Coldairarrow.IBusiness;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base_leasesystem_merchant
{
    /// <summary>
    /// 客户信息控制器
    /// </summary>
    [Route("/Base_leasesystem_merchant/[controller]/[action]")]
    [OpenApiTag("客户信息控制器")]
    public class leasesystem_merchantController : BaseApiController
    {
        #region DI

        public leasesystem_merchantController(Ileasesystem_merchantBusiness leasesystem_merchantBus,IOperator @operator)
        {
            _leasesystem_merchantBus = leasesystem_merchantBus;
              _operator=@operator;
            //_mer_img = mer_img;

        }

        Ileasesystem_merchantBusiness _leasesystem_merchantBus { get; }
        IOperator _operator { get; }
        //Ileasesystem_merchant_imgBusiness _mer_img { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<leasesystem_merchant>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _leasesystem_merchantBus.GetDataListAsync(input,_operator.UserId);
        }

        /// <summary>
        /// 编辑页面的连表查询 根据id连表  客户银行信息表，客户表
        /// </summary>
        /// <param name="input">id</param>
        /// <returns></returns>
        [HttpPost]
        public object GetEditAll(IdInputDTO input)
        {
            var obj = _leasesystem_merchantBus.GetListAll(input.id);
            return obj;
        }

        [HttpPost]
        public async Task<leasesystem_merchant> GetTheData(IdInputDTO input)
        {
            return await _leasesystem_merchantBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 客户表下拉框填充
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public List<SelectModel> FullSelect() 
        {
            return _leasesystem_merchantBus.FullSelect();
        }

        [HttpPost]
        public object GetHeightSearch(PageInput<ConditionDTO> input)
        {
            return _leasesystem_merchantBus.GetHeightSearch(input);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task<string> SaveData(leasesystem_merchant data)
        {

            if (data.Id.IsNullOrEmpty())
            {
                data.CheckStatus = 0;
                InitEntity(data);

                await _leasesystem_merchantBus.AddDataAsync(data);
                return data.Id;
            }
            else
            {
                await _leasesystem_merchantBus.UpdateDataAsync(data);
                return "0";
            }
        }


        /// <summary>
        /// 提交客户信息数据    同时添加客户银行、开票信息
        /// </summary>
        /// <param name="merchant"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task AddMer_bank_invoiceinfo(MerchantAll merchant)
        {
            InitEntity(merchant);
            merchant.CheckStatus = 0;
            await  _leasesystem_merchantBus.AddMer_bank_invoiceinfo(merchant);
        }

        /// <summary>
        /// 编辑客户信息数据   同时更改客户银行、开票信息
        /// </summary>
        /// <param name="merchant"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task EditMer_bank_invoiceinfo(MerchantAll merchant) 
        {
            await _leasesystem_merchantBus.EditMer_bank_invoiceinfo(merchant);
        }


        [HttpPost]
        [ApiPermission("merchant.Delete")]
        public async Task DeleteData(List<string> ids)
        {
            await _leasesystem_merchantBus.DeleteDataAsync(ids);
        }

        //public async Task GetMerchantDetailInfo() 
        //{
        //    await _leasesystem_merchantBus.GetMerchantDetailInfo();
        //}
        #endregion
    }
}